﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace InstantSpine.Core.MaterialModels
{
    /// <summary>
    /// Corresponding force-deflection values characterizing the
    /// behavior of some material
    /// </summary>
    /// <remarks>This data type is isomorphic to Tuple´2[double, double].
    /// The only reason for its existence is to enable automatic column
    /// generation by WPF's datagrid control </remarks>
    [DataContract]
    public class ForceDeflectionPair: INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        private double force;
        private double deflection;

        // read/write for two-way binding
        /// <summary>
        /// Measured force
        /// </summary>
        [DataMember]
        public double Force {
            get { return force; }
            set {
                if (force != value) {
                    force = value;
                    PropertyChanged.Raise(this);
                }
            }
        }

        // read/write for two-way binding
        /// <summary>
        /// Measured deflection
        /// </summary>
        [DataMember]
        public double Deflection {
            get { return deflection; }
            set {
                if (deflection != value) {
                    deflection = value;
                    PropertyChanged.Raise(this);
                }
            }
        }

        // required so that WPF datagrid can add rows
        // required for XML serialization to work
        public ForceDeflectionPair() {
        }

        public ForceDeflectionPair(double force, double deflection) {
            this.force = force;
            this.deflection = deflection;
        }

        public static implicit operator ForceDeflectionPair(Tuple<double, double> forceDeflection) {
            return new ForceDeflectionPair(forceDeflection.Item1, forceDeflection.Item2);
        }
    }    
}
